/**
 * 对外提供MC动画调用方法
 */
class MC {
    /**
   * 单例存储
   */
    private static P: MC = null;
    private mc_arr: Array<any> = new Array<any>();
    /**
     * 已注册MC存储
     */
    private png;
    private json;

    /**
     * 注册mc动画
     * visend 动画播完消失不
     */
    public initmoveclipe(json: string, png: string, nicheng: string, mcname: string, com: any, visend: boolean): egret.MovieClip {
        this.json = RES.getRes(json);
        this.png = RES.getRes(png);
        let mcFactory: egret.MovieClipDataFactory = new egret.MovieClipDataFactory(this.json, this.png);
        let s: egret.MovieClip = new egret.MovieClip(mcFactory.generateMovieClipData(mcname));
        s.visible
        if (visend == false) {
            s.addEventListener(egret.Event.COMPLETE, (e: egret.Event) => {
                s.visible = false;
            }, this);
        }
        com.addChild(s);

        this.mc_arr.push({ name: nicheng, mc: s });
        return s;
    }
    
    /**
     * 设置mc的xy和显隐(为指示小手用)
     */
    public setxyv(name: string, x: number, y: number, vis: boolean) {
        this.mc_arr.forEach((v, i) => {
            if (v.name == name) {
                v.mc.x = x;
                v.mc.y = y;
                v.visible = vis;
            }
        })

    }

    /**
     * 播放
     */
    public play(name: string, playtime: number) {
        this.mc_arr.forEach((v, i) => {
            if (v.name == name) {
                v.mc.play(playtime);
            }
        })
    }
    /**
     * 停止
     */
    public stop(name: string) {
        this.mc_arr.forEach((v, i) => {
            if (v.name == name) {
                v.mc.gotoAndStop(0);
            }
        })
    }

    /*
    * 对内提供返回实例确保单例
    */
    public static getinstance() {
        if (this.P == null) {
            this.P = new MC();
        }
        return this.P;
    }

}